/**
 * Cookie.setMaxAge() 如果設為 0, 表示我們要刪除這個 cookie, 接下來也就是覺得矛盾的地方, 那就是要使用 addCookie() , 
 * 通知 Browser , 這個 cookie 已被刪除(事實上就是將原來的 Cookie 設定為立即過期)
 */
package cookie.delete;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.e885.log.E885Logger;

/**
 * url:http://127.0.0.1:8080/JSP/cookie/deleteCookie<br>
 * <br>
 * 刪除名稱為 "DeleteCookie" 的 Cookie
 * 
 * @author Grady.Kao
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2000-2008
 */

public class CookieDeleter extends HttpServlet
{
	private static final long serialVersionUID = 4446606258992996611L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		E885Logger.testLog.debug( "execute CookieDeleter.service() to add cookie." );

		Cookie cookie = new Cookie( "DeleteCookie", "" );
		cookie.setDomain( "127.0.0.1" );
		cookie.setPath( "/JSP" );
		cookie.setMaxAge( 0 );
		cookie.setVersion( 0 );
		cookie.setSecure( false );

		response.addCookie( cookie );

		response.setContentType( "text/html; charset=UTF-8" );
		PrintWriter writer = response.getWriter();
		writer.println( "Delete Cookie 已經完成" );
		writer.close();
	}
}
